package com.staka.website.pages.user;

import java.util.List;

import org.apache.tapestry5.alerts.AlertManager;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.staka.website.entities.User;
import com.staka.website.pages.Index;

public class Login {
	@Property
	private User user;
	@Inject
	private Session session;
	@InjectComponent
	private Zone zone;
	@Inject
	private AlertManager alertmanager;
	
	
	Object onSuccess(){
		List<User> u = session.createCriteria(User.class).add(Restrictions.eq("email", user.getEmail())).add(Restrictions.eq("password", user.getPassword())).list();
		if (u!=null) {
			if(u.size()>0){
			//	System.out.println(u.size());
			//	System.out.println(u.get(0).getFirstname());
				return Index.class;
			}else{
				alertmanager.info("Wrong email or password");
			}
		}
		return null;
	}
	
	
}
